<template>
	<view class="container">
		<TopBtn :title="'常用处方'"></TopBtn>
		<searchBar @chenge="chenge"></searchBar>
		<view class="listBox">
			<view class="list" v-for="n in list" :key="n.id" @click="act=n.id">
				<view class="chnage">
					<image v-if="n.id==act" src="@/static/cooperate/xz.png" mode=""></image>
					<text v-else></text>
				</view>
				<view class="info">
					<view class="title flex-center">
						<image src="@/static/cooperate/cyf.png" mode=""></image>
						rp
					</view>
					<view class="text rowShow_2">
						{{n.recipelName}}
					</view>
				</view>
			</view>
		</view>
		<view class="CommonToolsbtn flex-center-center" @click="goinfo(act)">
			选择
		</view>
		<view class="kong">

		</view>
	</view>
</template>

<script>
	import {
		getDoctorRecipelPage,
		createDoctorAppoint,
		deleteDoctorPrescription
	} from '@/api/commonTools'
	export default {
		data() {
			return {
				act: null,
				list: [],
				request: {
					pageNo: 1,
					pageSize: 10,
				},
				maxNum: "",
			};
		},
		onLoad() {
			this.getDoctorRecipelPage()
		},
		onReachBottom() {
			if (this.maxNum <= this.request.pageNo) return
			this.request.pageNo = this.request.pageNo + 1
			this.getDoctorRecipelPage()
		},
		methods: {
			chenge(e) {
				console.log(e)
				this.request.prescriptionName = e
				this.list = []
				this.request.pageNo = 1
				this.getDoctorRecipelPage()
			},
			getDoctorRecipelPage() {
				getDoctorRecipelPage(this.request).then(res => {
					this.list.push(...res.data.list)
					let num = res.data.total / this.request.pageSize
					if (num.toString().includes('.')) {
						num = Math.ceil(num)
					}
					this.maxNum = num
				})
			},

			del(id) {
				var _this = this
				uni.showModal({
					title: '提示',
					content: '是否确认删除',
					success: function(res) {
						if (res.confirm) {
							deleteDoctorPrescription(id).then(res => {
								_this.list = []
								_this.request.pageNo = 1
								_this.getDoctorRecipelPage()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					},
				})
			},
			goinfo(id) {
				if (!id) {
					uni.showToast({
						title: '请选择',
						duration: 2000,
						icon: 'none',
					})
					return
				}
				uni.$emit('DoctorRecipel', id)
				uni.navigateBack({
					delta: 1
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.listBox {
		margin-top: 43rpx;
		padding: 0 30rpx;

		.info {
			flex: 1;
		}

		.list {
			width: 690rpx;
			height: 182rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			padding: 20rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-bottom: 30rpx;
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;

			.chnage {
				text {
					display: inline-block;
					width: 27rpx;
					height: 27rpx;
					margin-right: 23rpx;
					background: #FFFFFF;
					border-radius: 50%;
					border: 1px solid #EEEEEE;
					box-sizing: border-box;
				}

				image {
					width: 27rpx;
					margin-right: 23rpx;
					height: 27rpx;
				}
			}

			.title {
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
				margin-bottom: 12rpx;

				image {
					width: 30rpx;
					height: 30rpx;
					margin-right: 5rpx;
					margin-right: 17rpx;
				}
			}


		}
	}
</style>